{ "cells": [ { "cell_type": "markdown", "id": "ec78990c", "metadata": {}, "source": [ "## File paths" ] }, { "cell_type": "markdown", "id": "0e24085d", "metadata": {}, "source": [ "- Windows filenames: \n", " - Uses backslash\n", " - C:\\some_folder\\some_file.txt\n", "\n", "- Most other operating systems:(UNIX,Linux)\n", " - Forward slash\n", " - /some_folder/some_file.txt\n", " \n", "- Reason:The forward slash character was already taken by UNIX when windows was made so they used a backslash instead." ] }, { "cell_type": "markdown", "id": "9014bc33", "metadata": {}, "source": [ "- Relative path: The path relative to the folder we are currently working in.\n", "- Absolute path: The path that is relative to the operating system" ] }, { "cell_type": "markdown", "id": "9f1a190f", "metadata": {}, "source": [ "- If you want your Python code to work on both Windows and Mac/Linux, you’ll need to deal with these kinds of platform-specific issues. \n", "\n", "- Luckily, Python 3 has a new module called pathlib that makes working with files nearly painless." ] }, { "cell_type": "markdown", "id": "74fda22b", "metadata": {}, "source": [ "- we have to provide path \n", "- path->all directories+file name\n", "\n", "- If we just give file name\n", " - Python considers it relative\n", " - relative to cwd (os.cwd)\n", " - For absolute path\n", " - Linux: Starts with (/) /home/alarm/filename.txt \n", " - starts with C:\\" ] }, { "cell_type": "markdown", "id": "36c4c863", "metadata": {}, "source": [ "- you can use os module or pathlib module or defining paths manually(worst) for the same" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }